$(document).ready(function(){
    if(sessionStorage.getItem("msg_data")==null){
        alert("您的登录信息已过期请重新登陆");
        window.location.href="http://172.18.80.9:8087/admin/login/login"
    }
    // 分页
    var setTotalCount = 301;
    $('#box').paging({
        initPageNo: 3, // 初始页码
        totalPages: 30, //总页数
        totalCount: '合计' + setTotalCount + '条数据', // 条目总数
        slideSpeed: 600, // 缓动速度。单位毫秒
        jump: true, //是否支持跳转
        callback: function(page) { // 回调函数
            // console.log(page);
        }
    })
    var msg_data =JSON.parse(sessionStorage.getItem("msg_data"));
    // 立项项目列表
    $.ajax({
        type: "POST",
        dataType:"json",
        data:{uid:msg_data.id,token:msg_data.token},
        url: "http://172.18.80.9:8087/admin/research/researchlist",
        success: function (data) {
            if(data.code==9){
                alert(data.msg)
                window.location.href="http://172.18.80.9:8087/admin/login/login"
                return false;
            }
         var html=""
            for(var tmp of data.data){
             html+=`
                  <tr>
                    <td>${tmp.item_no}</td>
                    <td>${tmp.project_type}</td>
                    <td>${tmp.project_name}</td>
                    <td>${tmp.begin_time}</td>
                    <td>${tmp.end_time}</td>
                    <td>${tmp.belong_company}</td>
                    <td>${tmp.total_money}</td>
                    <td>
                        <div class="btnn" id="look" data-id="${tmp.id}" style="cursor:pointer">
                            <img src="../images/look.png" alt="" style="cursor:pointer">
                        </div>
                     </td>
                  </tr> 
             `
            }
            $("#tbody1").html(html);
        },
        error: function (err) {
            console.log(err);
            alert("网络故障请检查");
        }
    });
    // 查询项目
    $(document).on("click","#search",function (e) {
        e.preventDefault();
        var project_name=$("#select").val();
            $.ajax({
                type: "POST",
                dataType:"json",
                data:{project_name:project_name,uid:msg_data.id,token:msg_data.token},
                url: "http://172.18.80.9:8087/admin/principal/search",
                success: function (data) {
                    if(data.data.code==9){
                        alert(data.data.msg)
                        return false;
                    }
                    var html=""
                    for(var tmp of data.data){
                        html+=`
                  <tr>
                    <td>${tmp.item_no}</td>
                    <td>${tmp.project_type}</td>
                    <td>${tmp.project_name}</td>
                    <td>${tmp.begin_time}</td>
                    <td>${tmp.end_time}</td>
                    <td>${tmp.belong_company}</td>
                    <td>${tmp.total_money}</td>
                    <td>
                        <div class="btnn" id="look" data-id="${tmp.id}" style="cursor:pointer">
                            <img src="../images/look.png" alt="" style="cursor:pointer">
                        </div>
                     </td>
                  </tr> 
             `
                    }
                    $("#tbody1").html(html);
                },
                error: function (err) {
                    console.log(err);
                    alert("网络故障请检查");
                }
            });

    })
    //查看项目按钮
    $(document).on("click","#look",function (e) {
        e.preventDefault();
        var eid =$(this).data("id");
        //应该跳到一个新的页面
        window.location.href="http://172.18.80.9:8087/admin/principal/projectdetail?"+"id="+encodeURI(eid);
    })
})



